package com.sxj.corejava.code09_集合.Map集合;

import java.util.Enumeration;
import java.util.Hashtable;

/**
 * @author 石小俊
 * @date 2024年05月09日 18:54
 */
public class Test04_Hashtable {
    public static void main(String[] args) {
        Hashtable<Integer, String> map = new Hashtable<>();
        map.put(1, "admin");
        // key与value均不能为null
        // map.put(null,"aaa");
//        map.put(2,null);
        map.put(2, "alice");
        map.put(3, "tom");
        map.put(4, "jack");
        map.put(5, "lucy");
        System.out.println(map);

        Enumeration<Integer> keys = map.keys();
        while (keys.hasMoreElements()) {
            Integer key = keys.nextElement();
            String value = map.get(key);
            System.out.println("key:" + key + ",value:" + value);
        }

        Enumeration<String> elements = map.elements();
        while (elements.hasMoreElements()){
            String value = elements.nextElement();
            System.out.println("value:"+value);
        }

    }

}
